package com.test;

import com.pojo.NurseContent;
import com.pojo.NurseLevel;
import com.pojo.User;
import com.service.NurseContentService;
import com.service.NurseLevelService;
import com.service.UserService;

import java.util.List;
import java.util.Scanner;

public class View {
    private UserService userService = new UserService();
    private NurseLevelService nurseLevelService = new NurseLevelService();
    private NurseContentService nurseContentService = new NurseContentService();
    Scanner input = new Scanner(System.in);
    //系统启动方法,首页
    public void index(){
        while (true){

            System.out.println("*********欢迎来到yy健康中心************");
//            System.out.println("1 护理级别");
//            System.out.println("--1.1 护理级别添加");
//            System.out.println("--1.2 护理级别显示");
//            System.out.println("--1.3 护理级别修改");
//            System.out.println(" 护理项目");
//            System.out.println("--2.1 护理项目添加");
//            System.out.println("--2.2 护理项目显示");
//            System.out.println("--2.3 护理项目修改");
//            System.out.println("--2.4 护理项目删除");
            System.out.println("1 用户模块");
            System.out.println("--1.1 登录");
            System.out.println("--1.2 添加");
            System.out.println("--1.3 分页");
            System.out.println("--1.4 删除");
            System.out.println();
            System.out.println("2 护理项目");
            System.out.println("--2.1 护理项目添加");
            System.out.println("--2.2 护理项目删除");
            System.out.println("--2.3 护理项目查询-分页");

            System.out.println();
            System.out.println("3 退出系统");
            System.out.println("******************************");
            System.out.println("请选择");
            String choice = input.next();
            switch (choice){
                case "1.1":
                    //
                    //登录--成功,
                    if (login()){

                        System.out.println("登录成功!!");
                    }else {
                        System.out.println("登录失败!!");

                    }
                    break;
                case "1.2":
                    //
                    addUser();
                    break;
                case "1.3":
                    //
                    showUser();
                    break;
                case "1.4":
                    //
                    deleteUser();

                    break;
                case "2.1":
                    //
                    addNurseContent();
                    break;
                case "2.2":
                    //
                    deleteNurseContent();

                    break;
                case "2.3":
                    showNurseContent();
                    //editNurseContent();
                    break;

                case "3":
                    //

                    System.out.println("exit!");
                    return;
                default:
                    System.out.println("菜单选择有误! 重新选择");
            }
        }

    }

    private void deleteUser() {
        System.out.println("请输入要删除的账号名称:");
        String username = input.next();
        userService.deleteUser(username);
        System.out.println("账号删除成功!");
    }

    private void showUser() {
        List<User> users = userService.searchAll();
        System.out.println("序号\t\t账号\t密码\t性别\t系统角色编号（1-管理员 2-健康管家）");
        for (User u : users){
            System.out.println(u.getId()+"\t"+u.getUsername()+"\t"
                    +u.getPassword()+"\t"+u.getSex()+"\t"+u.getRoleId());
        }
    }

    private void addUser() {
        User user = new User();

        System.out.println("请输入新的账号名称:");
        user.setUsername(input.next());
        System.out.println("请输入新的账号密码:");
        user.setPassword(input.next());
        System.out.println("请输入性别:（0：女  1：男）");
        user.setSex(input.nextInt());

        //调用业务层添加
        userService.addUser(user);
        System.out.println("添加成功!");
    }



    private void deleteNurseContent() {
        //NurseContent content = new NurseContent();
        System.out.println("请输入要删除的护理项目编号:");
        int id = input.nextInt();
        nurseContentService.deleteNurseContent(id);
        System.out.println("护理级别删除成功!");
    }

    private void editNurseContent() {
        NurseContent content = new NurseContent();
        System.out.println("请输入要修改的护理项目编号:");
        content.setId(input.nextInt());
        System.out.println("请输入护理项目的序列号:");
        content.setSerialNumber(input.next());
        System.out.println("请输入护理项目名称:");
        content.setNursingName(input.next());
        System.out.println("请输入护理项目的价格:");
        content.setServicePrice(input.next());
        System.out.println("请输入护理项目的备注:");
        content.setMessage(input.next());
        System.out.println("请输入护理项目的执行周期:");
        content.setExectionCycle(input.next());
        System.out.println("请输入护理项目的执行次数:");
        content.setExectionTime(input.next());
        System.out.println("请输入护理状态:");
        content.setStatus(input.nextInt());
        //调用业务层修改护理等级
        nurseContentService.updateNurseContent(content);
        System.out.println("护理级别修改成功!");
    }

    private void showNurseContent() {
        List<NurseContent> contents = nurseContentService.searchAll();
        System.out.println("序号\t\t项目编号\t价格\t执行周期\t执行次数\t状态\t备注");
        for (NurseContent content : contents){
            System.out.println(content.getId()+"\t"+content.getSerialNumber()+"\t"
                    +content.getServicePrice()+"\t"+content.getExectionCycle()+"\t"+content.getExectionTime()
                    +"\t"+content.getStatus()+"\t"+content.getMessage());
        }
    }

    //添加护理项目
    private void addNurseContent() {
        NurseContent content = new NurseContent();
        System.out.println("请输入护理项目的序列号:");
        content.setSerialNumber(input.next());
        System.out.println("请输入护理项目名称:");
        content.setNursingName(input.next());
        System.out.println("请输入护理项目的价格:");
        content.setServicePrice(input.next());
        System.out.println("请输入护理项目的备注:");
        content.setMessage(input.next());
        System.out.println("请输入护理项目的执行周期:");
        content.setExectionCycle(input.next());
        System.out.println("请输入护理项目的执行次数:");
        content.setExectionTime(input.next());
        System.out.println("请输入护理状态:");
        content.setStatus(input.nextInt());
        //调用业务层添加
        nurseContentService.addNurseContent(content);
        System.out.println("添加成功!");
    }

    private void editNurseLevel() {
        NurseLevel level = new NurseLevel();
        System.out.println("请输入护理级别编号:");
        level.setId(input.nextInt());
        System.out.println("请输入护理等级名称:");
        level.setLevelName(input.next());
        System.out.println("请输入护理状态(1启用 2停用):");
        level.setLevelStatus(input.nextInt());
        //调用业务层修改护理等级
        nurseLevelService.updateNurseLevel(level);
        System.out.println("护理级别修改成功!");
    }

    private void showNurseLevel() {
        List<NurseLevel> levels = nurseLevelService.searchAll();
        System.out.println("编号\t护理级别名称\t护理状态");
        for (NurseLevel level : levels){
            System.out.println(level.getId()+"\t"+level.getLevelName()+"\t"+level.getLevelStatus());
        }
    }

    private void addNurseLevel() {
        NurseLevel level = new NurseLevel();
        System.out.println("请输入护理等级名称:");
        level.setLevelName(input.next());
        System.out.println("请输入护理状态(1启用 2停用):");
        level.setLevelStatus(input.nextInt());
        //调用业务层添加护理等级
        nurseLevelService.addNurseLevel(level);
        System.out.println("护理级别添加成功!");

    }

    private boolean login() {
        System.out.println("请输入用户名:");
        String username = input.next();
        System.out.println("请输入密码:");
        String password = input.next();
        //调用业务层查询方法
        User user = userService.searchByUnameAndPwd(username,password);
        if (user != null)
            return true;
        else return false;
    }

}
